package test.restful;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class TaskManager {
    private static TaskManager instance = new TaskManager();
    private static final Map<String, Task> tasks = Collections
            .synchronizedMap(new HashMap<String, Task>());

    /* Initialize some tasks with hard-coded values */
    static {
        tasks.put("1", new Task("1", "Walk the dog", "Remember the leash", "Today"));
        tasks.put("2", new Task("2", "Go to the store", 
            "Buy milk and eggs", "Apr 1, 2010"));
    };

    private TaskManager() {
    }
    
    public static TaskManager getInstance() {
        return instance;
    }
    
    public Collection<Task> getTasks() {
        return Collections.unmodifiableCollection(tasks.values());
    }
    
    public Task getTask(String id) {
        return tasks.get(id);
    }
    
    public void addTask(String id, Task task)
    {
        tasks.put(id, task);
    }

}
